<?php
namespace api\know\controller;

use api\wxapp\controller\PublicController;
use api\know\model\MaterialModel;
use api\know\model\TeachingMaterialContentModel;
use api\know\model\ResourceModel;
use api\know\model\TeachingMaterialKnowledgePointModel;
use api\know\model\TeachingMaterialNewWordModel;
use api\know\model\KnowledgePointModel;
use api\know\model\NewWordModel;
use api\know\model\NewWordQuestionModel;
use api\know\model\QuestionModel;
use think\facade\Log;

class NewWordController extends PublicController
{
    public function detail()
    {
        $uuid = $this->request->param('uuid', '');
		if (empty($uuid))
        {
            $this->error('知识点不能为空!');
        }

        $kp_wh[] = ['is_delete', '=', 0];
        $kp_wh[] = ['is_enable', '=', 1];
        $kp_wh[] = ['uuid', '=', $uuid];

        $w = NewWordModel::where($kp_wh)->field(NewWordModel::$QueryField)->find();
		if (empty($w)) 
		{
			$this->error('词汇不存在!');
		}
        $w['analysis'] = htmlspecialchars_decode(htmlspecialchars_decode($w['analysis']));
        $lst = NewWordQuestionModel::where('new_word_uuid', '=', $uuid)->field(NewWordQuestionModel::$QueryField)->select()->toArray();

        $questions = [];
        foreach($lst as $v)
        {
            $item = QuestionModel::getQuestion($v['question_uuid']);
            array_push($questions, $item);
        }

        $this->success('请求成功!', [
            'content' => $w,
            'question' => $questions,
        ]);
    }

}
